// printer.js
const SERVER_URL = "http://";

export const sendPrintRequest = (computerId, content) => {
	return new Promise((resolve, reject) => {
		const payload = {
			computer_id: computerId,
			content: content,
			timestamp: Math.floor(Date.now() / 1000)
		};

		uni.request({
			url: `${SERVER_URL}/send_print_task`,
			method: 'POST',
			data: JSON.stringify(payload), // 关键修改：手动序列化
			header: {
				'Content-Type': 'application/json',
			},
			success: (res) => {
				console.log('完整响应:', res);
				if (res.statusCode === 200 && res.data?.status === 'success') {
					resolve(res.data);
				} else {
					reject(res.data?.message || '服务器返回错误');
				}
			},
			fail: (err) => {
				console.error('请求失败:', err);
				reject('网络请求失败: ' + err.errMsg);
			}
		});
	});
};